<?php

namespace api\modules\v1\controllers\buss;

use common\helpers\CommonHelper;
use services\linkedcare\LinkedcareChannelService;
use services\spoker\SpokerService;
use services\user\UserWithdrawAccountService;
use Yii;
use api\controllers\OnAuthController;
use yii\db\Exception;
use yii\web\HttpException;

class SpokerController extends OnAuthController
{
    public $modelClass = '';

    /**
     * @api {get} /v1/buss/spoker/index 代言人列表
     * @apiGroup Spoker
     * @apiName index
     * @apiUse CommonParam
     *
     * @apiParam {string} keywords
     * @apiParam {int} status
     * @apiParam {int} page
     * @apiParam {int} pageSize
     *
     * @apiSuccess {Object}  data
     * @apiSuccess {Object}  data.list                  列表数据
     * @apiSuccess {Number}  data.list.id               列表ID
     * @apiSuccess {String}  data.list.name             名称
     * @apiSuccess {String}  data.list.mobile           手机号
     * @apiSuccess {String}  data.list.referrer_name    推荐人
     * @apiSuccess {Number}  data.list.status           状态【0待审核、1审核通过、2审核拒绝】
     * @apiSuccess {String}  data.list.status_name      状态名称
     * @apiSuccess {String}  data.list.all_num          新增数量
     * @apiSuccess {String}  data.list.in_hospital_num  到院数量
     * @apiSuccess {String}  data.list.sale_money       总销售额
     * @apiSuccess {String}  data.list.created_at_str   提交日期
     *
     */
    public function actionIndex()
    {
        $params = Yii::$app->request->get();

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;
        $service = new SpokerService();
        $list['list'] = $service->spokerList($params, $page, $pageSize);
        $list['condition'] = $service->getStatusCondition();
        return $list;

    }

    /**
     * @throws Exception
     * @api {post} /v1/buss/spoker/examine 代言人审核
     * @apiGroup Spoker
     * @apiName examine
     * @apiUse CommonParam
     *
     * @apiBody {Number}   id                  代言人ID
     * @apiBody {Number}   status              审核结果【通过：1 拒绝：2】
     *
     * @apiSuccess {Number} data    代言人ID
     */
    public function actionExamine()
    {
        $params = Yii::$app->request->post();
        if (!isset($params['id']) || !$params['id']) {
            return CommonHelper::api(422, '请选择代言人');
        }
        if (!isset($params['status']) || !$params['status']) {
            return CommonHelper::api(422, '请选择审核结果');
        }
        $service = new SpokerService();
        return $service->examine($params);
    }

    /**
     * @api {get} /v1/buss/spoker/account 提现账号
     * @apiGroup Spoker
     * @apiName account
     * @apiUse CommonParam
     *
     * @apiParam {int} id           代言人ID
     *
     * @apiSuccess {Object}  data
     * @apiSuccess {Object}  data                  列表数据
     * @apiSuccess {Number}  data.id               列表ID
     * @apiSuccess {Number}  data.type             类型【1支付宝、2银行】
     * @apiSuccess {Number}  data.card_no          账号
     * @apiSuccess {Number}  data.name             名称
     * @apiSuccess {Number}  data.bank_name        银行【type=2存在】
     *
     */
    public function actionAccount(): array
    {
        $id = Yii::$app->request->get('id');
        if (!isset($id) || !$id) {
            return CommonHelper::api(422, '请选择代言人');
        }
        $service = new SpokerService();
        return $service->getSpokerAccount($id);
    }
}
